<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
            canvas{
                border:1px solid black;
            }
        </style>
</head>
<body>
        <canvas width=600 height=400 id="cas"></canvas>
        <script>
        var cas = document.getElementById("cas");
        var ctx = cas.getContext("2d")
        var x = 100;
        var y = 100;
        var h = 100;
        var w = 100;
        var step = 5;
        var timer = setInterval(function(){
            ctx.clearRect(x,y,h,w);
            x+=step;
            if(x>=400){
                x=400;
                clearInterval(timer);
            }
            ctx.fillRect(x,y,h,w)
          
        },20)
        </script>
</body>
</html>